//
//  FSInputRootView.m
//  Trade
//
//  Created by 刘沿 on 16/4/12.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSInputRootView.h"
#import "FSInputOpinionView.h"

@implementation FSInputRootView

-(void)awakeFromNib{
    FSInputOpinionView * inputOpinionView = [FSInputOpinionView inputOpinionView];
    inputOpinionView.frame = CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 44);
    [self addSubview:inputOpinionView];
    
}
-(void)updata:(NSArray*)array{
//    NSMutableArray * dataArray = [NSMutableArray array];
    for (NSInteger index = 0 ; index < array.count; index++) {
        NSDictionary * dict = array[index];

        FSInputOpinionView * inputOpinionView = self.subviews[index];
    inputOpinionView.nameTextField.text  = dict[@"name"];
        inputOpinionView.jobTitleTextField.text  = dict[@"work_phone"];
        inputOpinionView.connectMethodTextField.text  = dict[@"tel"];
        inputOpinionView.beizutextfield.text  = dict[@"demo"];

               //[dataArray addObject:dict];
    }
    
}

-(void)addInputOpinionView{
    FSInputOpinionView * inputOpinionView = [FSInputOpinionView inputOpinionView];
    [self addSubview:inputOpinionView];
    
}

-(void)layoutSubviews{
    [super layoutSubviews];
    CGFloat y = 0;
    for (NSInteger index = 0 ; index < self.subviews.count; index++) {
        FSInputOpinionView * inputOpinionView = self.subviews[index];
        inputOpinionView.frame = CGRectMake(0, y,[UIScreen mainScreen].bounds.size.width, 44);
        y += 44;
        inputOpinionView.tag = index;
    }
}

-(CGFloat)inputRootViewHeight{
    CGFloat height = 0;
    for (NSInteger index = 0 ; index < self.subviews.count; index++){
        height += 44;
    }
    return height;
}

-(NSMutableArray*)getInfo{
    NSMutableArray * dataArray = [NSMutableArray array];
//    NSMutableDictionary * dict = [NSMutableDictionary dictionary];
    for (NSInteger index = 0 ; index < self.subviews.count; index++) {
        NSMutableDictionary * dict = [NSMutableDictionary dictionary];

        FSInputOpinionView * inputOpinionView = self.subviews[index];
        if ([inputOpinionView.nameTextField.text length] !=0) {
            [dict setObject:inputOpinionView.nameTextField.text forKey:@"name"];
        }
        
        if ([inputOpinionView.jobTitleTextField.text length]) {
            [dict setObject:inputOpinionView.jobTitleTextField.text forKey:@"jobTitle"];
        }

        if ([inputOpinionView.beizutextfield.text length]) {
            [dict setObject:inputOpinionView.beizutextfield.text forKey:@"demo"];
        }


        
        if ([inputOpinionView.connectMethodTextField.text length]) {
            [dict setObject:inputOpinionView.connectMethodTextField.text forKey:@"connectMetod"];
        }
        
        [dataArray addObject:dict];
    }
    
    return dataArray;
}

@end
